﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace DAL
{
    public class RecipeCategory
    {
        public static void insert(RecipeCategoryEntity recipeCategory)
        {
            DbHelper.ExecuteNonQuery("p_RecipeCategory_insert",
                recipeCategory.Name,
                recipeCategory.ParentId,
                recipeCategory.TreeLevel,
                recipeCategory.Sort,
                recipeCategory.IsShow
            );
        }

        public static void update(RecipeCategoryEntity recipeCategory)
        {
            DbHelper.ExecuteNonQuery("p_RecipeCategory_update",
                recipeCategory.Rcid,
                recipeCategory.Name,
                recipeCategory.ParentId,
                recipeCategory.TreeLevel,
                recipeCategory.Sort,
                recipeCategory.IsShow
            );
        }

        public static void delete(int rcid)
        {
            DbHelper.ExecuteNonQuery("p_RecipeCategory_delete", rcid);
        }

        public static RecipeCategoryEntity getById(int rcid)
		{
			DataRow dr = DbHelper.ExecuteDataRow("p_recipeCategory_getById", rcid);
			RecipeCategoryEntity recipeCategory = new RecipeCategoryEntity();
			if (dr != null)
			{
				recipeCategory.Rcid=int.Parse(dr["rcid"].ToString());
				recipeCategory.Name=dr["name"].ToString();
				recipeCategory.ParentId=int.Parse(dr["parentId"].ToString());
                recipeCategory.TreeLevel = short.Parse(dr["treeLevel"].ToString());
				recipeCategory.Sort=int.Parse(dr["sort"].ToString());
				recipeCategory.IsShow=bool.Parse(dr["isShow"].ToString());
			}
			return recipeCategory;
		}
    }
}